package com.gitee.swsk33.mapstructdemo.structmapper;

import com.gitee.swsk33.mapstructdemo.dataobject.GuildDO;
import com.gitee.swsk33.mapstructdemo.dto.GuildDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

/**
 * 用于公会数据层对象和传输层对象的映射
 */
@Mapper
public interface GuildMapper {

	GuildMapper INSTANCE = Mappers.getMapper(GuildMapper.class);

	/**
	 * 定义一个将公会数据层对象转换成DTO对象的接口方法
	 */
	@Mapping(target = "guildName", source = "name")
	GuildDTO toGuildDTO(GuildDO guildDO);

	/**
	 * 定义一个将公会DTO转换成数据层对象的接口方法
	 */
	@Mapping(target = "name", source = "guildName")
	GuildDO toGuildDO(GuildDTO guildDTO);

	/**
	 * 自定义的DO转DTO逻辑
	 */
	default GuildDTO customDOToDTO(GuildDO guildDO) {
		if (guildDO == null) {
			return null;
		}
		GuildDTO guildDTO = new GuildDTO();
		guildDTO.setId(guildDO.getId());
		guildDTO.setGuildName("公会：" + guildDO.getName());
		return guildDTO;
	}

}